package com.danceforyou.user.service.impl;

import com.danceforyou.common.service.impl.BaseServiceImpl;
import com.danceforyou.user.dao.RoleMenuDAO;
import com.danceforyou.user.model.RoleMenuDO;
import com.danceforyou.user.service.RoleMenuService;
import com.danceforyou.user.vo.RoleMenuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* 类名称：RoleMenuServiceImpl
* 创建人：danceforyou
* 创建时间：2021年01月12日
* 版本号：1.0v
*/
@Service("roleMenuService")
public class RoleMenuServiceImpl extends BaseServiceImpl<Long, RoleMenuDO, RoleMenuVO, RoleMenuDAO> implements RoleMenuService {
    @Autowired
    private RoleMenuDAO roleMenuDAO;

    @Override
    public RoleMenuDAO getDao() {
        return roleMenuDAO;
    }

    @Override
    public void saveRoleMenu(Long roleId, String menuIds) {
        this.deleteByProperty("roleId", roleId);
        String[] menuIdArr = menuIds.split(",");
        for (String menuId : menuIdArr) {
            RoleMenuDO roleMenu = new RoleMenuDO();
            roleMenu.setRoleId(roleId);
            roleMenu.setMenuId(Long.parseLong(menuId));
            roleMenuDAO.insert(roleMenu);
        }
    }

    @Override
    public RoleMenuVO getRoleMenuByBacklog(Long roleId, String backlogKey) {
        return roleMenuDAO.getRoleMenuByBacklog(roleId, backlogKey);
    }
}
